/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package SpringTAI.service;

/**
 *
 * @author Krzysztof Nyznar
 */

import org.springframework.validation.Validator;
import org.springframework.validation.Errors;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class AddPersonValidator implements Validator {

    /** Logger for this class and subclasses */
    protected final Log logger = LogFactory.getLog(getClass());

    public boolean supports(Class clazz) {
        return AddPerson.class.equals(clazz);
    }

    public void validate(Object obj, Errors errors) {
        AddPerson ap = (AddPerson) obj;
        if (ap == null) {
            errors.rejectValue("name", "error.not-specified", null, "Pole wymagane!");
        }
        else {
            if (ap.getName().isEmpty()) {
                errors.rejectValue("name", "error.not-specified", null, "Pole wymagane!");
            }
            if (ap.getSurname().isEmpty()) {
                errors.rejectValue("surname", "error.not-specified", null, "Pole wymagane!");
            }
            
            if (ap.getAddress().isEmpty()) {
                errors.rejectValue("address", "error.not-specified", null, "Pole wymagane!");
            }
            
        }
    }

}